package doInterce.impl;

import cn.hutool.core.io.FileUtil;
import doInterce.DoInterface;
import utils.ExceptionUtil;
import utils.PathUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 获取单位封面信息
 * @Author: syh
 * @Date: 2024/01/23/14:52
 */
public class DoGetUnitInfo implements DoInterface {
    @Override
    public void doRun(Connection connection,String customParam){
        //抽取封面
        String resultFilePath = PathUtil.getOutFilePathByFileName("需要返还市组织部的文件.txt");
        try {

            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("select RPTID, UNITID, BSDW, FZR, BSSJ, TBR, LXDH, SJ from tb_rpt_cv_cfg where  RPTID='J2308' order by  UNITID");
            List<String> contentList = new ArrayList<>();
            while (resultSet.next()){
                String RPTID=resultSet.getString(1);
                String UNITID=resultSet.getString(2);
                String BSDW=resultSet.getString(3);
                String FZR=resultSet.getString(4);
                String BSSJ=resultSet.getString(5);
                String TBR=resultSet.getString(6);
                String LXDH=resultSet.getString(7);
                String SJ=resultSet.getString(8);
                String sql = "INSERT INTO TB_RPT_CV_CFG (RPTID, UNITID, BSDW, FZR, BSSJ, TBR, LXDH, SJ) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');";

                String content = String.format(sql,RPTID, UNITID, BSDW, FZR, BSSJ, TBR, LXDH, SJ);
                contentList.add(content);
            }

            FileUtil.writeLines(contentList,resultFilePath,"utf-8");

        }catch (Exception e){
            System.out.println("系统出现异常！");
            ExceptionUtil.writeLog(e);
        }
    }
}
